package com.iqik.base.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class Demo01 extends Object {

    static AtomicInteger atomicInteger = new AtomicInteger(0);

    public static volatile int num = 0;


    public static void m1() {
        atomicInteger.addAndGet(1);
//        atomicInteger.getAndIncrement();
    }

    public static void demo01(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    m1();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    m1();
                }
            }
        }).start();

        Thread.sleep(1000);
        System.out.println(atomicInteger);
    }


    public static void main(String[] args) throws CloneNotSupportedException {
        A a = new A();
        System.out.println(a);
        a.setA(1);
        System.out.println(a.getA());
        System.out.println(a);

        a = new A();
        a.setA(2);
        System.out.println(a);
        System.out.println(a.getA());
    }
}


class A {
    private int a;

    public int getA() throws CloneNotSupportedException {
        System.out.println(this.clone());
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }
}